﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     BaseData业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/11/11
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class BaseDataSqlMapDao : BaseSqlMapDao, IBaseDataDao
    {
        private static BaseDataSqlMapDao instance = null;
        private static object syncRoot = new object();

        private BaseDataSqlMapDao()
        {
            //
            // TODO: 此处添加BaseDataSqlMapDao的构造函数
            //
        }
        public static IBaseDataDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new BaseDataSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectBaseDataByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<BaseData> GetList()
        {
            try
            {
                return ExecuteQueryForList<BaseData>("SelectBaseData", null);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 通过DataID like 出所需要的结果集
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<BaseData> GetListByDataID(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<BaseData>("SelectBaseDataByDataID", objParameters);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<BaseData> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<BaseData>("SelectBaseDataByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="DataID"></param>
        /// <returns></returns>
        public BaseData GetDetail(BaseData data)
        {
            try
            {
                return ExecuteQueryForObject<BaseData>("SelectBaseData", data) as BaseData;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="basedata"></param>
        /// <returns></returns>
        public object Add(BaseData basedata)
        {
            //int id = GetId("BaseData");
            //basedata.DataID = id;

            try
            {
                return ExecuteInsert("InsertBaseData", basedata);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="basedata"></param>
        /// <returns></returns>
        public int Update(BaseData basedata)
        {
            try
            {
                return ExecuteUpdate("UpdateBaseData", basedata);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="DataID"></param>
        /// <returns></returns>
        public int Delete(System.String dataid)
        {
            try 
            {
                return ExecuteDelete("DeleteBaseData", dataid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="basedata"></param>
        /// <returns></returns>
        public int Delete(BaseData basedata)
        {
            try
            {
                return ExecuteDelete("DeleteBaseData", basedata.DataID);
            }
            catch
            {
                throw;
            }
        }


        public ArrayList GetKeyList()
        {
            try
            {
                return ExecuteQueryForList("SelectAllKeys", null) as ArrayList ;
            }
            catch 
            {
                
                throw;
            }
        }
    }
}
